/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.swt.mto.thithu.service.impl;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.model.User;
import com.swt.mto.thithu.model.Result;
import com.swt.mto.thithu.service.base.ResultLocalServiceBaseImpl;

/**
 * The implementation of the result local service.
 *
 * <p>
 * All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy their definitions into the {@link com.swt.mto.thithu.service.ResultLocalService} interface.
 *
 * <p>
 * This is a local service. Methods of this service will not have security checks based on the propagated JAAS credentials because this service can only be accessed from within the same VM.
 * </p>
 *
 * @author tuan.nguyen
 * @see com.swt.mto.thithu.service.base.ResultLocalServiceBaseImpl
 * @see com.swt.mto.thithu.service.ResultLocalServiceUtil
 */
public class ResultLocalServiceImpl extends ResultLocalServiceBaseImpl {
	
	
	public Result addResult(User userId, long quizId, int numberSentenceCorrect, int totalSentence, double score){
		Result result = null;
		try {
			result = resultLocalService.createResult(counterLocalService.increment(Result.class.getName()));
			result.setUserId(userId.getUserId());
			result.setQuizId(quizId);
			result.setNumSentenceCorrect(numberSentenceCorrect);
			result.setTotalSentence(totalSentence);
			result.setScore(score);
			
			resultPersistence.update(result, false);
		} catch (SystemException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return result;
	}
}